/**
 * @author Erik
 **/

/*
 *  This is an abstract superclass for all activities in our application
 *  that will host one fragment. This way we ensure that each activity will
 *  implement FragmentActivity from Android support library and corresponding
 *  Fragment code.
 *  NOTE: We will use two-pane view for larger devices
 *  and consider consider this view SimpleFragmentActivity as well 
 *  
 *  Each SingleFragmentActivity will inflate empty layout defined in 
 *  activity_manager.xml with its fragment created by method 
 *  createFragment().
 *   
 */

package sk.stuba.fei.ut.snmpmanager;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;

public abstract class SingleFragmentActivity extends FragmentActivity
{
	// Used to setContentView to a layout
	protected int getLayoutId()
	{
		// activity_manager.xml is just an empty layout with fragmentContainer
		return R.layout.activity_manager;
	}

	@Override
	protected void onCreate( Bundle savedInstanceState )
	{
		super.onCreate( savedInstanceState );
		setContentView( getLayoutId() );
		FragmentManager fm = getSupportFragmentManager();
		// find Fragment to manage
		Fragment fragment = fm.findFragmentById( R.id.fragmentContainer );
		// when activity is recreated recreate the fragment
		if ( fragment == null )
		{
			fragment = createFragment();
			fm.beginTransaction().add( R.id.fragmentContainer, fragment )
					.commit();
		}
	}

	// Each SingleFragmentActivity must implement a way to create a fragment
	protected abstract Fragment createFragment();

}
